package com.lzw.bluetoothpractice.Activitys;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.Adapters.RecoveryAction2ListAdapter;
import com.lzw.bluetoothpractice.Adapters.RecoveryActionList3Adapter;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.Utils.AppUtil;
import com.lzw.bluetoothpractice.Utils.SharePreferenceUtils;
import com.lzw.bluetoothpractice.bean.HosptialBean;
import com.lzw.bluetoothpractice.bean.PlanBean;
import com.lzw.bluetoothpractice.bean.PlandetailBean;
import com.lzw.bluetoothpractice.network.HeadAssmblyUtils;
import com.lzw.bluetoothpractice.network.RetrofitManager;
import com.lzw.bluetoothpractice.network.api.RequestApi;

import java.util.Map;

import androidx.recyclerview.widget.LinearLayoutManager;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static com.lzw.bluetoothpractice.MyApplication.getContext;

public class PlanDetailActivity extends BaseActivity {
    private Map<String, String> keyMap;
    private  Intent intent;
    TextView name;
    TextView detail;
    TextView content;
    ImageView pic;

    String planId;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.plan_detail);
        intent=getIntent();
        planId=  intent.getStringExtra("planId");

       // Log.e("article",article.toString());
        InitNavBar2(true,"计划详情",false);
        InitView();
        initPlan();



    }
    public void InitView(){
        name=fd(R.id.name);

        detail=fd(R.id.detail);

        content=fd(R.id.content);

        pic=fd(R.id.pic);


    }
    private void initPlan(){
        try {
            keyMap = HeadAssmblyUtils.HeadAssembly("/dev-api/android/plan/getInfoForAndroid");
        } catch (Exception e) {
            e.printStackTrace();
        }
        String accessToken = SharePreferenceUtils.getString(getContext(),"access_token",null);;
        String userid = SharePreferenceUtils.getString(getContext(),"userId",null);
        RetrofitManager.getInstance(AppConfig.BASE_URL)
                .createReq(RequestApi.class).getPlanById(Long.parseLong(planId),"1", AppUtil.getVersionCode() + "", accessToken ,keyMap.get("gmtStr"), keyMap.get("contentMD5"), keyMap.get("hmacCode")).
                observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

                Log.e("计划2：",e.getMessage()+"");

            }

            @Override
            public void onNext(JSONObject json) {

                PlandetailBean planBean = JSON.parseObject(json.toString(), PlandetailBean.class);
                if(planBean.getCode()==200){

                    name.setText(planBean.getData().getName());

                    detail.setText(planBean.getData().getDescri());
                    content.setText(Html.fromHtml(planBean.getData().getContent()));
                    Glide.with(PlanDetailActivity.this).load(AppConfig.BASE_URL+planBean.getData().getPic()).into(pic);



                }else {
                    Toast toast=Toast.makeText(getContext(),"查询计划详情失败",Toast.LENGTH_LONG);
                    toast.show();
                }


            }
        });

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
       // isCltSatus=false;
      //  clt=false;
    }


}
